<template>
	<view>
		<view class="u-demo-wrap u-p-l-30 u-p-r-20 u-p-b-30">
			<u-form :model="model" ref="uForm" style="width: 100%;">
				<u-form-item left-icon="grid" style="padding: 0px;" label-width="120" label="设备:">
					{{getTyp(model.equipId)}}
					<u-tag slot="right" :text="getPri(model.priority)" />
				</u-form-item>
				<u-form-item label-width="130" style="padding: 0px;" label="问题描述:">{{model.trouble}}</u-form-item>
				<u-form-item label-width="130" style="padding: 0px;" label="故障图片:">
					<u-image v-for="(item, index) in model.urls" height="200rpx" :key="index" :src="item" mode="aspectFit"></u-image>
				</u-form-item>
				<u-form-item label-width="130" style="padding: 0px;" label="发生日期:">{{model.occurrence}}
				</u-form-item>
				<u-form-item label-width="130" style="padding: 0px;" label="详细地址:">{{model.address}}</u-form-item>
			</u-form>
		</view>
		<view class="u-flex user-box u-p-l-30 u-p-r-20 u-p-b-30">
			<u-form :model="model" ref="uForm" style="width: 100%;">
				<u-form-item label-width="130" label="维修内容:"><u-input v-model="model.maintenance" type="textarea" /></u-form-item>
				<u-form-item label-width="130" label="原因分析:"><u-input v-model="model.reason" type="textarea" /></u-form-item>
				<u-form-item label-width="130" label="维修完成:"><u-switch v-model="checked"></u-switch></u-form-item>
			</u-form>
		</view>
		<u-gap height="20"></u-gap>
		<view class="btn-line"><button class="landing" v-show="visible" type="primary" style="width: 90%;" @click="bindConfirm">提交</button></view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			visible:false,
			checked: true,
			radioList: [
				{
					name: '一般',
					value: 1
				},
				{
					name: '紧急',
					value: 2
				},
				{
					name: '报警',
					value: 3
				}
			],
			model: {},
			type: []
		};
	},
	onLoad(option) {
		this.model.id = option.id;
		this.request({
			url: 'BaseEquipment/pages',
			data: {
				limit: 0
			},
			success: res => {
				this.type = res.data;
			}
		});
		this.initData();
	},
	methods: {
		getTyp(id) {
			let typ = this.type.find(m => m.code == id);
			if (typ != undefined) {
				return typ.name;
			} else {
				return '请选择设备';
			}
		},
		getPri(id) {
			let typ = this.radioList.find(m => m.value == id);
			if (typ != undefined) {
				return typ.name;
			} else {
				return '';
			}
		},
		initData() {
			if (this.model != undefined && this.model.id != undefined) {
				this.request({
					url: 'EamOrder/detail',
					data: {
						id: this.model.id
					},
					success: res => {
						this.model = res.data;
						if (this.model.status == 1){
							this.visible = true;
						}
					}
				});
			}
		},
		bindConfirm() {
			if (this.model.maintenance == undefined || this.model.maintenance == '') {
				this.$u.toast('请输入维修内容');
				return;
			}
			if (this.checked){
				this.model.status = 2;
			}
			this.request({
				url: 'EamOrder/edit',
				method: 'POST',
				data: this.model,
				success: res => {
					if (res.code == 200) {
						if (res.data == '1') {
							uni.navigateBack();
						}
					} else {
						this.$u.toast(res.msg);
					}
				}
			});
		}
	}
};
</script>

<style lang="scss">
	.landing{
		height: 84upx;
		line-height: 84upx;
		border-radius: 44upx;
		font-size: 32upx;
		background: linear-gradient(left,#FF978D, #FFBB69);
	}
</style>
